<template>
  <el-dialog append-to-body title="撤回与放弃" :visible="visible" @close="handleClose" width="40%">
    <el-form ref="form" :model="abandonForm" :rules="abandonRule" class="white-card" label-width="110px">
      <el-form-item label="放弃类型：" prop="type">
        <el-select v-model="abandonForm.type" placeholder="请选择">
          <el-option v-for="item in dictList" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="放弃原因：" prop="reason">
        <el-input type="textarea" v-model="abandonForm.reason" maxlength="300" show-word-limit :autosize="{ minRows: 4 }"></el-input>
      </el-form-item>
    </el-form>
    <div class="split"></div>

    <div class="dialog-footer-btn">
      <el-button @click="handleClose" type="primary" plain>关闭</el-button>
      <el-button type="primary" @click="handleGiveUp" :loading="submitting">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import * as mixins from "@/utils/mixins";
import * as workOrderApi from "@/api/workOrder/index";
import * as dictApi from "@/api/dict";
import * as templateApi from "@/api/template";

export default {
  name: "AbandonComplaint",
  mixins: [mixins.loading, mixins.form, mixins.dialog],
  props: ["visible", "details"],
  components: {},
  data() {
    return {
      abandonForm: {
        type: "",
        reason: "",
      },
      abandonRule: {
        type: [{ required: true, message: "请选择" }],
        reason: [{ required: true, message: "请填写" }],
      },
      submitting: false,
      dictList: [],
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    show() {
      /* 
        放弃投诉原因	1019
      */
      templateApi.detailByCode(1019).then((res) => {
        this.abandonForm.reason = res.result.value;
      });
      this.getDictList();
    },
    getDictList() {
      dictApi
        .list({ parentCode: "1020" })
        .then((res) => {
          this.dictList = res.result;
        })
        .finally(() => {});
    },
    handleGiveUp() {
      this.validateAndConfirm("form")
        .then((res) => {
          this.submitting = true;
          return workOrderApi.all.giveUp({
            workOrderNo: this.details.workOrderNo,
            giveUpType: this.abandonForm.type,
            giveUpReason: this.abandonForm.reason,
          });
        })
        .then(() => {
          this.$emit("success");
          this.handleClose();
        })
        .finally(() => {
          this.submitting = false;
        });
      /* this.$refs.abandonForm
        .validate((valid) => {
          if (valid) {
            this.submitting = true;
            return workOrderApi.all.giveUp({
              workOrderNo: this.details.workOrderNo,
              giveUpType: this.abandonForm.type,
              giveUpReason: this.abandonForm.reason,
            });
            .then((r) => {
              this.dialogFormVisible4 = false;
              this.playLoadData();
              this.$message.success(r.msg);
            });
          }
        })
        .then(() => {
          this.$emit("success");
          this.handleClose();
        })
        .finally(() => {
          this.submitting = false;
        }); */
    },
  },
};
</script>
<style lang="less" scoped>
.el-select {
  width: 100%;
}
</style>
